var t = wx.getSystemInfoSync().screenWidth / 750;

Component({
    options: {
        styleIsolation: "apply-shared",
        multipleSlots: !0
    },
    properties: {
        items: {
            type: Array,
            value: []
        },
        fixed: {
            type: Boolean,
            value: !1
        },
        current: {
            type: Number,
            value: 0
        },
        styles: {
            type: Number,
            value: 0
        }
    },
    observers: {
        items: function(t, e) {
            t.length > 0 && this.initTab();
        }
    },
    data: {
        bar: {
            left: 0
        },
        nodes: [],
        scrollLeft: 0,
        width: "auto"
    },
    methods: {
        tabChange: function(t) {
            var e = this, a = t.currentTarget.dataset.id;
            a !== this.data.current && (this.setData({
                current: a
            }, function() {
                e.initTab();
            }), this.triggerEvent("onchange", {
                current: a
            }, {}));
        },
        setCurrent: function(t) {
            this.setData({
                current: t
            }, function() {
                this.initTab();
            });
        },
        initTab: function() {
            var e = this;
            wx.createSelectorQuery().in(this).selectAll(".tab-item").boundingClientRect(function(a) {
                if (1 === e.data.styles) {
                    if ("auto" == e.data.width) {
                        var i, n = a.length, r = 0;
                        a.forEach(function(t) {
                            r += t.width;
                        }), i = (r = (r = Math.ceil(r / t)) + 30 * (n - 1) + 60) + "rpx", e.setData({
                            width: i
                        });
                    }
                    var s = a[e.data.current], o = Math.ceil(30 * t) - a[0].left;
                    e.setData({
                        bar: {
                            left: s.left + o,
                            width: s.width
                        }
                    });
                } else e.setData({
                    nodes: a
                }, function() {
                    e.initBar();
                });
            }).exec();
        },
        initBar: function() {
            var t = this.data.nodes[this.data.current];
            t && this.setData({
                bar: {
                    left: t.left,
                    width: t.width
                }
            });
        }
    },
    attached: function() {}
});